package com.dareway.thread;

public class Thread_interrupt {
    public static void main(String[] args) {
        Thread t = new Thread(()->{
            System.out.println("线程开始运行！");
            while (true){   //无限循环
                if(Thread.currentThread().isInterrupted()){   //判断是否存在中断标志
                    break;

//                    System.out.println("发现中断信号，复位，继续运行...");
//                    Thread.interrupted();  //复位中断标记（返回值是当前是否有中断标记，这里不用管）
                }
            }
//            System.out.println("线程被中断了！");
        });
        t.start();
        try {
            Thread.sleep(3000);
            t.interrupt();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
